#!./common/bats/bin/bats
# -*-sh-*-

load ./common/test_helper_functions
source ./common/functions || exit 1

if [ -s ./common/TEST_ENV ];then
    source ./common/TEST_ENV
fi

if [ -z $BEEGFS_TEST_PATH ];then
    ERROR "BeeGFS Test Path not defined (BEEGFS_TEST_PATH)"
    exit 1
elif [ ! -d $BEEGFS_TEST_PATH ];then
    ERROR "BeeGFS Test Path:$BEEGFS_TEST_PATH does not exist"
    exit 1
else
    export BEEGFS_TEST_PATH
fi


@test "[BeeGFS] beegfs-df - $BEEGFS_TEST_PATH" {
    run beegfs-df -p $BEEGFS_TEST_PATH
    assert_success
}

@test "[BeeGFS] set target count=2 test - $BEEGFS_TEST_PATH" {
    local testdir="tempdir-$RANDOM"

    run mkdir $BEEGFS_TEST_PATH/$testdir
    assert_success

    run beegfs-ctl --setpattern --numtargets=2 --chunksize=1m $BEEGFS_TEST_PATH/$testdir
    assert_success

    echo "atest" > $BEEGFS_TEST_PATH/$testdir/afile
    run ls $BEEGFS_TEST_PATH/$testdir/afile
    assert_success

    # verify correct stripe settings for file in directory 
    beegfs-ctl --getentryinfo  $BEEGFS_TEST_PATH/$testdir/afile | egrep "Number of storage|Chunksize" >& .cmd_output
    run cat .cmd_output
    assert_output "+ Chunksize: 1M
+ Number of storage targets: desired: 2; actual: 1"

    rm -rf $BEEGFS_TEST_PATH/$testdir
}


